package UI;


import obj.All;

import javax.swing.*;
import java.awt.*;

public class control extends JFrame {
    public static short  width =500;
    public static final short heigth=500;
    public JLabel score;//得分
    public jpanel jp;
    public All all;
    public control(){
        JFrame jf=new JFrame();
        JLabel jl=new JLabel("按按钮开始游戏");
        jf.setLayout(null);
        jf.setLocationRelativeTo(null);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setSize(800,600);
        jl.setFont(new Font("宋体",Font.BOLD,100));
        jl.setBounds(0,0,800,500);
        JButton jb=new JButton("开始");
        jb.setBounds(300,400,100,80);
        jb.setFont(new Font("宋体",Font.BOLD,30));
        jb.addActionListener((e)->{
            jf.dispose();
            start();
        });
        jf.add(jl);
        jf.add(jb);
        jf.setVisible(true);

    }
    public void start(){
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(500,500);
        setTitle("game");
        setLayout(null);
        all=new All();
        //demo

        score=new JLabel("得分："+all.scores+"  声明："+all.user.GetLife());
        score.setBounds(0,0,500,20);
        add(this.score);

        jp=new jpanel(this,all);
        jp.setBounds(0,0,width,heigth);
        add(jp);

        setVisible(true);

        jp.requestFocusInWindow();
        jp.addKeyListener(new Keylist(all));
    }
    public void GameOver(){
        JOptionPane.showMessageDialog(this,"你失败了，得分："+all.scores,"你失败了", JOptionPane.ERROR_MESSAGE);
        dispose();
    }
}
